<script setup lang="ts">
import { ref } from 'vue'
import { User, ShoppingBag, Star, Setting, Bell } from '@element-plus/icons-vue'
import type { Component } from 'vue'

interface MenuItem {
  key: string
  label: string
  icon: Component
}

interface Props {
  activeKey?: string
}

interface Emits {
  (e: 'change', key: string): void
}

const props = withDefaults(defineProps<Props>(), {
  activeKey: 'profile'
})

const emit = defineEmits<Emits>()

const menuItems = ref<MenuItem[]>([
  { key: 'profile', label: '个人资料', icon: User },
  { key: 'orders', label: '我的订单', icon: ShoppingBag },
  { key: 'favorites', label: '我的收藏', icon: Star },
  { key: 'settings', label: '账户设置', icon: Setting },
  { key: 'notifications', label: '通知消息', icon: Bell }
])

const handleMenuClick = (key: string) => {
  emit('change', key)
}
</script>

<template>
  <div class="side-menu">
    <div
      v-for="item in menuItems"
      :key="item.key"
      class="menu-item"
      :class="{ active: activeKey === item.key }"
      @click="handleMenuClick(item.key)"
    >
      <el-icon class="menu-icon" :size="20">
        <component :is="item.icon" />
      </el-icon>
      <span class="menu-label">{{ item.label }}</span>
    </div>
  </div>
</template>

<style scoped>
.side-menu {
  background: rgba(255, 255, 255, 0.95);
  border-radius: 16px;
  padding: 12px;
  box-shadow: 0 4px 16px rgba(79, 172, 254, 0.1);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  color: var(--text-primary);
  font-size: 15px;
  font-weight: 500;
}

.menu-item:hover {
  background: linear-gradient(135deg, rgba(79, 172, 254, 0.08) 0%, rgba(0, 242, 254, 0.08) 100%);
  transform: translateX(4px);
  color: var(--primary-color);
}

.menu-item.active {
  background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(79, 172, 254, 0.25);
}

.menu-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 24px;
  background: #ffd700;
  border-radius: 0 2px 2px 0;
}

.menu-icon {
  flex-shrink: 0;
}

.menu-label {
  flex: 1;
  white-space: nowrap;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .side-menu {
    flex-direction: row;
    overflow-x: auto;
    padding: 8px;
  }

  .menu-item {
    flex-direction: column;
    padding: 12px 16px;
    gap: 6px;
    min-width: 80px;
    text-align: center;
  }

  .menu-item:hover {
    transform: translateY(-2px);
  }

  .menu-item.active::before {
    left: 50%;
    top: -2px;
    transform: translateX(-50%);
    width: 24px;
    height: 3px;
    border-radius: 0 0 2px 2px;
  }

  .menu-label {
    font-size: 13px;
  }
}
</style>
